const shutdown = require('electron-shutdown-command');
const { ipcRenderer } = require("electron");
const { exec } = require('child_process');
const os = require('os')

var webview = onload = () => {
   webview = document.querySelector('webview')
   console.log(webview)
}

//检查前进后退按钮状态
var checkStatus =  function() {
  if(!webview.canGoBack()) {
    document.querySelector('#goback').classList.add('disabled');
  } else {
    document.querySelector('#goback').classList.remove('disabled');
  }
  if(!webview.canGoForward()) {
    document.querySelector('#forward').classList.add('disabled');
  } else {
    document.querySelector('#goback').classList.remove('disabled');
  }
}
// 退出关机
document.querySelector('#exit').onclick = function() {
 document.querySelector('#confirmBox').style.display="flex";
}
// 退出关机
document.querySelector('#cancelBtn').onclick = function() {
 document.querySelector('#confirmBox').style.display="none";
}
// 退出关机
document.querySelector('#confirmBtn').onclick = function() {
 shutdown.shutdown(0);
}

// 返回 
document.querySelector('#goback').onclick = function() {
  if(webview.src.includes('/netwrok-course')) {
    webview.goToIndex(0);
  } else {
    webview.goBack();
  }
}

document.querySelector('webview').addEventListener('did-start-navigation', (e)=>{
  if(webview.canGoBack()) {
    document.querySelector('#goback').style.opacity = 1;
  } else {
    document.querySelector('#goback').style.opacity = 0;
  }
})

// // 调用软键盘
// document.querySelector('#keyboard').onclick = function () {
//   if (os.platform() === 'win32') {
//     exec('osk.exe',()=>{
//       ipcRenderer.send("show-win");
//     })
//   }
// }